﻿using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarPresentation.Dialogs
{
    /// <summary>
    /// PageHeaderEditor.xaml 的交互逻辑
    /// </summary>
    public partial class PageHeaderEditor : Window
    {
        public PageHeaderEditor(string pageHeaderLeft, string pageHeaderMiddle, string pageHeaderRight)
        {
            InitializeComponent();

            this.tbxLeft.Text = pageHeaderLeft;
            this.tbxMiddle.Text = pageHeaderMiddle;
            this.tbxRight.Text = pageHeaderRight;

            this.tbxLeft.Focus();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        public string PageHeaderLeft
        {
            get { return tbxLeft.Text; }
        }

        public string PageHeaderRight
        {
            get { return tbxRight.Text; }
        }

        public string PageHeaderMiddle
        {
            get { return tbxMiddle.Text; }
        }

        private TextBox editingTextBox = null;

        private void btnInsertDate_Click(object sender, RoutedEventArgs e)
        {
            DateTime date = DateTime.Now;

            StringBuilder sb = new StringBuilder();
            sb.Append(date.Year.ToString() + "年" + date.Month.ToString() + "月" + date.Day.ToString() + "日");

            if (this.editingTextBox == tbxLeft)
            {
                tbxLeft.SelectedText = sb.ToString(); tbxLeft.Focus();
            }
            else if (this.editingTextBox == tbxMiddle)
            {
                tbxMiddle.SelectedText = sb.ToString(); tbxMiddle.Focus();
            }
            else if (this.editingTextBox == tbxRight)
            {
                tbxRight.SelectedText = sb.ToString(); tbxRight.Focus();
            }
            else
            {
                tbxLeft.Focus();
            }
        }

        private void btnInsertTime_Click(object sender, RoutedEventArgs e)
        {
            DateTime date = DateTime.Now;
            StringBuilder sb = new StringBuilder();
            sb.Append(date.Hour.ToString() + "时" + date.Minute.ToString() + "分" + date.Second.ToString() + "秒");

            if (this.editingTextBox == tbxLeft)
            {
                tbxLeft.SelectedText = sb.ToString(); tbxLeft.Focus();
            }
            else if (this.editingTextBox == tbxMiddle)
            {
                tbxMiddle.SelectedText = sb.ToString(); tbxMiddle.Focus();
            }
            else if (this.editingTextBox == tbxRight)
            {
                tbxRight.SelectedText = sb.ToString(); tbxRight.Focus();
            }
            else
            {
                tbxLeft.Focus();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void tbxLeft_GotFocus(object sender, RoutedEventArgs e)
        {
            this.editingTextBox = tbxLeft;
        }

        private void tbxMiddle_GotFocus(object sender, RoutedEventArgs e)
        {
            this.editingTextBox = tbxMiddle;
        }

        private void tbxRight_GotFocus(object sender, RoutedEventArgs e)
        {
            this.editingTextBox = tbxRight;
        }
    }
}
